<?php
require_once "../connexion.php";
require_once '../Model/devisModel.php';
require_once "../Model/userModel.php";
//Appel au singleton Connexion
$maConnexion = ConnexionSingleton::getInstance();
$maConnexion->Connect();
?>
<?php 
if(isset($_GET["suppression"]))
{
	$id_devis = $_POST["id_devis"];
	$devis = new devisModel();
	if($devis->deleteDevis($id_devis))
	{
		echo "Le devis n&deg; $id_devis &agrave; &eacute;t&eacute; supprim&eacute;";
	}
	else
	{
		echo "Erreur lors de la suppression";
	}
}
if(isset($_GET["ajouter"]))
{
		$date_devis = $_POST["date_devis"];
		$client_devis = $_POST["client_devis"];
		$montant_devis = $_POST["montant_devis"];
		$id_user = $_POST["id_user"];
		
		$date_fr = explode("/", $date_devis);

		$jour = $date_fr[0];
		$mois = $date_fr[1];
		$annee = $date_fr[2];
		
		$dateEn = $annee."-".$mois."-".$jour;
		
		$devis = new devisModel();
		$devis->setMontant($montant_devis);
		$devis->setDate($dateEn);
		$devis->setClient($client_devis);
		$devis->setUtilisateur($id_user);
		
		$user = new userModel();
		
		if($devis->createDevis($devis))
		{	
			echo "<tr id='".$devis->getId()."' style='background:#fff;'>";
			echo "<td class='tab_td_style'>".$devis->getId()."</td>";
			echo "<td class='tab_td_style'>".$devis->getMontant()."</td>";
			echo "<td class='tab_td_style'>".$devis->getDate()."</td>";
			echo "<td class='tab_td_style'>".$devis->getClient()."</td>";
			echo "<td class='tab_td_style'>".$user->getUser($devis->getUtilisateur())."</td>";
			echo "<td class='tab_td_style'>";
			echo "<a class='delete'>";
			echo "<img src='css/images/supprimer.png' id='supression'>"; 
			echo "</a>";
			echo "</td>";
			echo "</tr>";	
		}
		else
		{
			echo "Un probl&eacute;me est survenue lors de l'ajout";
		}
	
}
?>